﻿<navCtl:Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:navCtl="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
  xmlns:fx="clr-namespace:BookClub.Core"
  xmlns:local="clr-namespace:BookClub.Pages"
  x:Class="BookClub.Pages.BookClub" 
  mc:Ignorable="d"
  d:DataContext="{d:DesignInstance Type=local:BookClubModel, IsDesignTimeCreatable=False}"
  d:DesignWidth="800" d:DesignHeight="600"
  Title="BookShelf">
  <navCtl:Page.Resources>
    <fx:Command x:Key="highlightsCommand" Method="ShowBooksOfDay" />
    <fx:Command x:Key="latestCommand" Method="ShowLatestBooks" />
    <fx:Command x:Key="searchCommand" Method="SearchBooks" />
    <fx:Command x:Key="moreCommand" Method="ShowMoreBooks" />
    <fx:Command x:Key="requestCommand" Method="RequestBook" />
    <fx:Command x:Key="likeCommand" Method="LikeBook" />
  </navCtl:Page.Resources>
  <Grid>
    <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
      <HyperlinkButton Style="{StaticResource linkButtonStyle}" Content="Today's Highlights"
       Command="{StaticResource highlightsCommand}" />
      <HyperlinkButton Style="{StaticResource linkButtonStyle}" Content="Latest Additions"
        Command="{StaticResource latestCommand}" />
      <TextBox x:Name="searchTextBox" Width="150" />
      <HyperlinkButton Style="{StaticResource searchButtonStyle}" VerticalAlignment="Center"
        Command="{StaticResource searchCommand}"
        CommandParameter="{Binding ElementName=searchTextBox, Path=Text}"/>
      <ComboBox Width="150" VerticalAlignment="Center"
        ItemsSource="{Binding Categories}" DisplayMemberPath="CategoryName"
        SelectedItem="{Binding SearchCategory, Mode=TwoWay}"/>
    </StackPanel>

    <Border Margin="0,30,20,60">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="200" />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock Style="{StaticResource headingText}" Grid.ColumnSpan="2"
          Text="{Binding Heading}" />

        <Grid Grid.Row="1" DataContext="{Binding SelectedBook}"
          Visibility="{Binding SelectedBook, Converter={StaticResource visibilityConverter}}">
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="10" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="6" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="6" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="6" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="6" />
            <RowDefinition Height="Auto" />
          </Grid.RowDefinitions>

          <Image Height="200" HorizontalAlignment="Right"
            Source="{Binding ASIN, Converter={StaticResource bookCoverLoader}}" />
          <TextBlock Style="{StaticResource listText}" Grid.Row="2" Margin="0,0,15,0"
            TextWrapping="Wrap" HorizontalAlignment="Right" TextAlignment="Right"
            Text="{Binding SharedBy, StringFormat='Shared by {0}'}" />
          <HyperlinkButton Style="{StaticResource linkButtonStyle}" Grid.Row="4"
            Margin="0,0,15,0" HorizontalAlignment="Right"
            Content="Request"
            Command="{StaticResource requestCommand}"
            CommandParameter="{Binding}"/>
          <TextBlock Style="{StaticResource listDetailText}" Grid.Row="6" Margin="0,20,15,0"
            TextWrapping="Wrap" HorizontalAlignment="Right" TextAlignment="Right"
            Text="{Binding Likes, StringFormat='{}{0} Members Liked this Book'}" />
          <HyperlinkButton Style="{StaticResource linkButtonStyle}" Grid.Row="8"
            Margin="0,0,15,0" HorizontalAlignment="Right"
            Content="Like"
            Command="{StaticResource likeCommand}"
            CommandParameter="{Binding}"/>
          <HyperlinkButton Style="{StaticResource linkButtonStyle}" Grid.Row="10"
            Margin="0,0,15,0" HorizontalAlignment="Right"
            Content="More on Amazon"
            TargetName="Amazon" NavigateUri="{Binding AmazonUri}"/>
        </Grid>

        <ListBox Grid.Row="1" Grid.Column="1" BorderThickness="0"
          ItemsSource="{Binding Books}"
          SelectedItem="{Binding SelectedBook, Mode=TwoWay}"
          ScrollViewer.HorizontalScrollBarVisibility="Disabled"
          ScrollViewer.VerticalScrollBarVisibility="Auto">
          <ListBox.ItemTemplate>
            <DataTemplate>
              <Grid Margin="0,0,0,5">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="450" />
                  <ColumnDefinition Width="150" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Style="{StaticResource listMainText}" Text="{Binding Title}" />
                <TextBlock Style="{StaticResource listText}" Grid.Column="1" HorizontalAlignment="Right"
                  TextAlignment="Right"
                  Text="{Binding StatusText}" />
                <StackPanel Grid.ColumnSpan="2" Grid.Row="1"
                  Visibility="{Binding IsSelected, Converter={StaticResource visibilityConverter}}">
                  <TextBlock Style="{StaticResource listDetailText}"
                    Text="{Binding Author}" />
                  <TextBlock Style="{StaticResource listDetailText}"
                    Text="{Binding Description, Converter={StaticResource truncator}}" />
                </StackPanel>
              </Grid>
            </DataTemplate>
          </ListBox.ItemTemplate>
        </ListBox>
      </Grid>
    </Border>

    <Border VerticalAlignment="Bottom" Height="32" Margin="0,0,20,20">
      <Grid>
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left"
          Text="{Binding Status}" FontFamily="Segoe UI" FontSize="14"/>
        <HyperlinkButton Style="{StaticResource linkButtonStyle}" Content="More"
          VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0"
          Command="{StaticResource moreCommand}" />
      </Grid>
    </Border>
  </Grid>
</navCtl:Page>
